#include <iostream>
#include <iomanip>

#include <fstream>

using namespace std;

int main(int argc, char **argv)
{
    char buffer[256];

    if(argc!=2)
    {
        cout << "Usage: readfile <filename> " <<endl;
        exit(1);
    }

    //生成ifstream的对象并打开文件
    ifstream input(argv[1], ios::in); // | ios::binary);

    //读取失败
    if(input.fail() )
    {
        cout << "can not open the file"<<endl;
        exit(1);
    }

    //依次读取sizeof(buffer)长度的数据，并输出
    do{
        //如果读取成功，则输出内容
        if(input.good() )
        {
           //input.read(buffer, sizeof(buffer));
           input.getline(buffer, sizeof(buffer));
           /*
           for(int i=0; i<sizeof(buffer); i++)
           {
               if(isprint(buffer[i]))
                 //cout << setw(3) << hex << (int)buffer[i] << " " << setw(3) << buffer[i] << " ";
                 cout << setw(3) << buffer[i] << " ";
               //else
               // cout << setw(8) << ".";
               if(i>0 && i%10==0)
                 cout <<endl;
           }
           */
           cout << buffer <<endl;
        }
    }while(!input.eof() );

    //关闭输入流
    input.close();
    return 0;
}
